<?php
declare(strict_types=1);

namespace App\Resource\Streamer\Task;


use App\Models\MainDB\MallProducts;
use Illuminate\Http\Resources\Json\JsonResource;

class RewardResource extends JsonResource
{
    public function toArray($request)
    {
        if(!isset($this->reward->prize->id)){
            return null;
        }

        return [
            "id" => $this->reward->prize->id,
            "type" =>  $this->reward->prize_type,
            "name" => $this->reward->prize_type == MallProducts::RELATION_TYPE ? $this->reward->prize->title : $this->reward->prize->name,
            "image" => $this->reward->prize->picture,
            "coin" => $this->reward->prize->price ?? 0,
            "count" => $this->count,
        ];
    }
}